package com.think.controller;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.think.domain.Condition;

@Controller
@SessionAttributes
public class ConditionViewController {

		@Autowired
		private ConditionModelController conditionModelController;
		
		@RequestMapping(value = "/addCondition", method = RequestMethod.POST)
		public String addCondition(@ModelAttribute("condition") Condition condition, BindingResult result){
			try {
				conditionModelController.insertCondition(condition, Locale.US.toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
			return "redirect:conditionData"; //Exit
		}
		
		@RequestMapping("/conditionData")
		public ModelAndView conditionFormEntry(){
			return new ModelAndView("conditionData", "command", new Condition()); //Exit
		}
}
